************************************************************************************************************************************************

********************** Do File for the paper "Policy congruence between parliaments and citizens of immigrant origin"***************************

************************************************************************************************************************************************


cd ///set your directory here
use "immigrant_congruence_data.dta", clear


************************************************************************************************************************************************
******************************************************* set time series data *******************************************************************
************************************************************************************************************************************************



egen country_id=group( policy_area country)

sort year
by country_id (year), sort: generate year_id=_n

sort country year
tsset  country_id year_id





************************************************************************************************************************************************
******************************************************* Models in table 1 **********************************************************************
************************************************************************************************************************************************



*** Model 1:

xtgls d.congruence_mig d.congruence_nomig d.representatives_mig representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store model1



*** Model 2:

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store model2



*** Model 3:

generate type=.
replace type=1 if closed_list==1&representatives_mig>7.5
replace type=2 if closed_list==0&representatives_mig>7.5
replace type=3 if closed_list==1&representatives_mig<7.5
replace type=4 if closed_list==0&representatives_mig<7.5

xtgls d.congruence_mig d.congruence_nomig d.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store model3



*** TABLE 1

esttab model1 model2 model3 using ///
"TABLE1.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 




************************************************************************************************************************************************
******************************************************* Figure 2 & 3***** **********************************************************************
************************************************************************************************************************************************



*** FIGURE 2 (based on Model 2)

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store model2

margins, dydx(d.representatives_mig) at( representatives_mig=(0 (0.5) 16)) noestimcheck
marginsplot



**** FIGURE 3 (based on Model 3)

xtgls d.congruence_mig d.congruence_nomig d.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store model3

margins, at(type=(2 3 4)) 
marginsplot, horizontal










************************************************************************************************************************************************
******************************************************* Appendix 5*************************************************************************
************************************************************************************************************************************************



*** Test 1

xtgls d.congruence_nonwestern d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_a5_1_m2

xtgls d.congruence_nonwestern d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_a5_1_m3


*** Test 2

xtgls d.congruence_western d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_a5_2_m2

xtgls d.congruence_western d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_a5_2_m3


*** TABLE APPENDIX 5.1
esttab rob_a5_1_m2 rob_a5_2_m2 using ///
"rob_tabA5_1.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ar2 ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 

*** TABLE APPENDIX 5.2
esttab  rob_a5_1_m3 rob_a5_2_m3 using ///
"rob_tabA5_2.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ar2 ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 










************************************************************************************************************************************************
******************************************************* Appendix 6&7*************************************************************************
************************************************************************************************************************************************



*** Test 1

mixed d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap || country: || year: 
estimates store rob_A6_1_m2

mixed d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap || country: || year: 
estimates store rob_A7_1_m3



*** Test 2

xtgls d.congruence_mig l.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A6_2_m2

xtgls d.congruence_mig l.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A7_2_m3



*** Test 3

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.immigrant_population d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A6_3_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type  d.immigrant_population d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A7_3_m3



*** Test 4

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.immigrant_nonwestern_population d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A6_4_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type  d.immigrant_nonwestern_population d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A7_4_m3




*** Test 5

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap foreign_population, panels(heteroskedastic)
estimates store rob_A6_5_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap foreign_population, panels(heteroskedastic)
estimates store rob_A7_5_m3



*** Test 6

generate ratio_foreign=foreign_population/(immigrant_population+foreign_population)

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap ratio_foreign, panels(heteroskedastic)
estimates store rob_A6_6_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap ratio_foreign, panels(heteroskedastic)
estimates store rob_A7_6_m3



*** Test 7

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap d.enp, panels(heteroskedastic)
estimates store rob_A6_7_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap d.enp, panels(heteroskedastic)
estimates store rob_A7_7_m3



*** Test 8

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap d.disproportionality, panels(heteroskedastic)
estimates store rob_A6_8_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap d.disproportionality, panels(heteroskedastic)
estimates store rob_A7_8_m3



*** Test 9

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap antidiscrimlaws, panels(heteroskedastic)
estimates store rob_A6_9_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap antidiscrimlaws, panels(heteroskedastic)
estimates store rob_A7_9_m3



*** Test 10

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap sd_immigrants, panels(heteroskedastic)
estimates store rob_A6_10_m2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap sd_immigrants, panels(heteroskedastic)
estimates store rob_A7_10_m3





*** TABLE APPENDIX 6.1
esttab rob_A6_1_m2 rob_A6_2_m2 rob_A6_3_m2 rob_A6_4_m2 rob_A6_5_m2  using ///
"rob_tabA6_3.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ar2 ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 

*** TABLE APPENDIX 6.2
esttab rob_A6_6_m2 rob_A6_7_m2 rob_A6_8_m2rob_A6_9_m2 rob_A6_10_m2 using ///
"rob_tabA6_2.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ar2 ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 

*** TABLE APPENDIX 7.1
esttab rob_A7_1_m2 rob_A7_2_m2 rob_A7_3_m2 rob_A7_4_m2 rob_A7_5_m2  using ///
"rob_tabA7_3.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ar2 ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 

*** TABLE APPENDIX 7.2
esttab rob_A7_6_m2 rob_A7_7_m2 rob_A7_8_m2rob_A7_9_m2 rob_A7_10_m2 using ///
"rob_tabA7_2.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) ar2 compress ///
legend label title(Regression models) ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 


















************************************************************************************************************************************************
******************************************************* Appendix 8******************************************************************************
************************************************************************************************************************************************


*** Test 1

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##cd.representatives_mig representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A8_1_m1



**** Test 2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig c.representatives_mig##c.representatives_mig closed_list d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A8_2_m1



*** TABLE APPENDIX 8.1
esttab rob_A8_1_m1 rob_A8_2_m1  using ///
"rob_tabA8.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 













************************************************************************************************************************************************
******************************************************* Appendix 9******************************************************************************
************************************************************************************************************************************************



*** Test 1

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig ib3.type, panels(heteroskedastic)
estimates store rob_A9_1_m3




*** Test 2

xtgls d.congruence_mig d.congruence_nomig cd.representatives_mig##c.representatives_mig ib3.type d.left_parties d.radicalright_parties d.participation_gap, panels(heteroskedastic)
estimates store rob_A9_2_m3



*** TABLE APPENDIX 9.1
esttab rob_A9_1_m1 rob_A9_2_m1  using ///
"rob_tabA9.rtf", ///
cells (b(star fmt(4)) se(par fmt(4))) compress ///
legend label title(Regression models) ///
star(a 0.15 * 0.10 ** 0.05 *** 0.01)  replace 
